package tree.binary;

import entity.tree.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class leetcode257二叉树的所有路径 {
    List<String> result = new ArrayList<>();
    public List<String> binaryTreePaths(TreeNode root) {
        dfs(root, "");
        return result;
    }

    public void dfs(TreeNode root, String str) {
        if (root == null) {
            return;
        }
        str += root.val;
        if (root.left == null && root.right == null) {
            result.add(str);
            return;
        }
        str += "->";
        dfs(root.left, str);
        dfs(root.right, str);
    }
}
